﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


/// <summary>
/// Summary description for clsKiemTraTrangThai
/// </summary>
public class clsKiemTraTrangThai
{
    SoLienLacDataContext db = new SoLienLacDataContext();
	public clsKiemTraTrangThai()
	{
		
	}
    public bool kiemtra(int manam, int malop, int mamon, int maky)
    {
        bool kt = true;
        var c = from p in db.TrangThaiBangDiems
                where p.MaKy == maky && p.MaLop == malop && p.MaMon == mamon && p.MaNam == manam
                select new { p.MaKy, p.MaMon, p.MaLop, p.MaNam };
        if (c.Count() == 0)
        {
            kt = false;
        }
        if (c.Count() != 0)
        { kt = true; }
        return kt;
    }
    public bool TTHoanThanh(int manam, int malop, int mamon, int maky)
    {
        bool tt = true;
        var c = from p in db.TrangThaiBangDiems
                where p.MaKy == maky && p.MaLop == malop && p.MaMon == mamon && p.MaNam == manam
                select p.TrangThaiHoanThanh;
        if (c.Count() != 0)
        {
            if (c.First() == null || c.First() == false)
            {
                tt = false;
            }
            if (c.First() == true)
            {
                tt = true;
            }
        }
        return tt;
    }
    public bool TTsua(int manam, int malop, int mamon, int maky)
    {
        bool tt = true;
        var c = from p in db.TrangThaiBangDiems
                where p.MaKy == maky && p.MaLop == malop && p.MaMon == mamon && p.MaNam == manam
                select p.ChuaSua;
        if (c.Count() != 0)
        {
            if (c.First() == null || c.First() == false)
            {
                tt = false;
            }
            if (c.First() == true)
            {
                tt = true;
            }
        }
        return tt;
    }
   public string trangthai(int manam, int malop, int mamon, int maky)
    {
        string tt1 = "";
        var c = from p in db.TrangThaiBangDiems
                where p.MaKy == maky && p.MaLop == malop && p.MaMon == mamon && p.MaNam == manam
                select new { p.TrangThaiHoanThanh, p.TrangThaiChoDuyet,p.DaSua,p.ChuaSua };
        if (c.Count() != 0)
        {
            if (c.First().TrangThaiHoanThanh == true)
            {
                tt1 = "Đã duyệt";

            }
            if (c.First().TrangThaiHoanThanh == false)
            {
                if (c.First().TrangThaiChoDuyet == true &&c.First().ChuaSua==false)
                {
                    tt1 = "Đang chờ duyệt";

                }
                if (c.First().TrangThaiChoDuyet == false && c.First().ChuaSua == true && c.First().DaSua == false)
                {
                    tt1 = "Cần sửa lại bảng điểm";

                }
                if (c.First().TrangThaiChoDuyet ==true && c.First().ChuaSua == true && c.First().DaSua == true)
                {
                    tt1 = "Cần sửa lại bảng điểm";

                }
                //if (c.First().ChuaSua == true && c.First().DaSua == false)
                //{
                //    tt1 = "Chưa sửa";
                //}
                if (c.First().ChuaSua == true&&c.First().DaSua==true)
                {
                    tt1 = "Đã sửa và đang chờ duyệt";
                }
            }
            if (c.First().TrangThaiHoanThanh == false)
            {
                if (c.First().TrangThaiChoDuyet == false&&c.First().ChuaSua==false)
                {
                    tt1 = "Chưa gửi bảng điểm";

                }
            }
           
        }
        if (c.Count() == 0)
        {
            tt1 = "Chưa gửi bảng điểm";
        }
        return tt1;

    }
   public string trangthaibangdiemcualophocky(int manam, int malop, int maky)
   {
       string tt1 = "";
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop && p.MaNam == manam
               select new { p.TrangThaiHoanThanh, p.TrangThaiChoDuyet,p.DaSua,p.TrangThaiHK};
       if (c.Count() != 0)
       {
           if (c.First().TrangThaiHoanThanh == true)
           {
               tt1 = "Đã duyệt";
               if (c.First().TrangThaiHK == true)
               {
                   tt1 = "Đã duyệt";
               }

           }
           if (c.First().TrangThaiHoanThanh == false)
           {
               if (c.First().TrangThaiChoDuyet == true&&c.First().DaSua==false)
               {
                   tt1 = "Đang chờ duyệt";

               }
               if (c.First().TrangThaiChoDuyet == true && c.First().DaSua == true)
               {
                   tt1 = "Đang chờ duyệt";

               }
               if (c.First().TrangThaiChoDuyet == false && c.First().DaSua == false)
               {
                   tt1 = "Cần sửa lại bảng kết quả";

               }
               if (c.First().TrangThaiChoDuyet == true &&c.First().TrangThaiHK==false)
               {
                   tt1 = "Cần sửa lại bảng kết quả";

               }
               
               
              
           }
          
           if (c.First().TrangThaiHoanThanh == false)
           {
               if (c.First().TrangThaiChoDuyet == false && c.First().DaSua == null)
               {
                   tt1 = "Chưa gửi bảng điểm";

               }
           }

       }
       if (c.Count() == 0)
       {
           tt1 = "Chưa gửi bảng điểm";
       }
       return tt1;

   }
   public string trangthaibanghanhkiem(int manam, int malop, int maky)
   {
       string tt1 = "";
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop && p.MaNam == manam
               select new { p.TrangThaiHoanThanh, p.TrangThaiHK };
       if (c.Count() != 0)
       {
           if (c.First().TrangThaiHoanThanh == true)
           {
               tt1 = "Đã duyệt";
               if (c.First().TrangThaiHK == true)
               {
                   tt1 = "Đã duyệt";
               }

           }
           if (c.First().TrangThaiHoanThanh == false)
           {
               if (c.First().TrangThaiHK == false)
               {
                   tt1 = "Cần sửa lại hạnh kiểm";

               }
               if (c.First().TrangThaiHK == null)
               {
                   tt1 = "Chưa gửi bảng hạnh kiểm";

               }
           }
       }
       if (c.Count() == 0)
       {
           tt1 = "Chưa gửi bảng hạnh kiểm";
       }

       return tt1;

   }
   public void NgayGuiBDHK(int manam, int malop, int maky, Label lbl)
   {
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop&& p.MaNam == manam
               select p.NgayGui;
       if (c.Count() != 0)
       {
           string a = c.First().ToString();
           lbl.Text = a.Substring(0, 10);
       }
   }
   public void NgayGuiBangHanhKiem(int manam, int malop, int maky, Label lbl)
   {
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop && p.MaNam == manam
               select p.NgayGuiHK;
       if (c.Count() != 0)
       {
           string a = c.First().ToString();
           lbl.Text = a.Substring(0, 10);
       }
   }
   public void NgayDuyetBDHK(int manam, int malop,int maky, Label lbl)
   {
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop  && p.MaNam == manam
               select p.NgayDuyet;
       if (c.Count() != 0)
       {
           string a = c.First().ToString();
           lbl.Text = a.Substring(0, 10);
       }
   }
   public string HienThiThongBaoBDHK(int manam, int malop, int maky)
   {
       string thongbao = "";
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop  && p.MaNam == manam
               select p.ThongBao;
       if (c.Count() != 0)
       {
           if (c.First() != null)
           {
               thongbao = c.First().ToString();
           }

       }
       return thongbao;
   }
   public void NgayGuiBD(int manam, int malop, int mamon, int maky,Label lbl)
   {
       var c = from p in db.TrangThaiBangDiems
               where p.MaKy == maky && p.MaLop == malop && p.MaMon == mamon && p.MaNam == manam
               select  p.NgayGuiBD ;
       if (c.Count() != 0)
       {
           string a = c.First().ToString();
           lbl.Text = a.Substring(0, 10);
       }
   }
   public void NgayDuyetBD(int manam, int malop, int mamon, int maky, Label lbl)
   {
       var c = from p in db.TrangThaiBangDiems
               where p.MaKy == maky && p.MaLop == malop && p.MaMon == mamon && p.MaNam == manam
               select p.NgayDuyetBD;
       if (c.Count() != 0)
       {
           string a = c.First().ToString();
           lbl.Text = a.Substring(0, 10);
       }
   }
   public string HienThiThongBao(int manam, int malop, int mamon, int maky)
   {
       string thongbao = "";
       var c = from p in db.TrangThaiBangDiems
               where p.MaKy == maky && p.MaLop == malop && p.MaMon == mamon && p.MaNam == manam
               select p.ThongBao;
       if (c.Count() != 0)
       {
           if (c.First() != null)
           {
               thongbao = c.First().ToString();
           }
           if (c.First() == null)
           {
               thongbao = "";
           }
           
       }
       if (c.Count() == 0)
       {
           thongbao = "";
       }
       return thongbao;
   }
   public string HienThiThongBaobdhk(int manam, int malop, int maky)
   {
       string thongbao = "";
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop && p.MaNam == manam
               select p.ThongBao;
       if (c.Count() != 0)
       {
           thongbao = c.First().ToString();

       }
       return thongbao;
   }
   public bool kiemtrabdhk(int manam, int malop, int maky)
   {
       bool kt = true;
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop  && p.MaNam == manam
               select new { p.MaKy, p.MaLop, p.MaNam };
       if (c.Count() == 0)
       {
           kt = false;
       }
       if (c.Count() != 0)
       { kt = true; }
       return kt;
   }
   public bool TTHoanThanhbdhk(int manam, int malop, int maky)
   {
       bool tt = true;
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop  && p.MaNam == manam
               select p.TrangThaiHoanThanh;
       if (c.Count() != 0)
       {
           if (c.First() == null || c.First() == false)
           {
               tt = false;
           }
           if (c.First() == true)
           {
               tt = true;
           }
       }
       return tt;
   }
  public void TrangThaiHK(int manam, int malop, int maky,CheckBox ckb)
   {
       var c = from p in db.TrangThaiBangDiemTheoKies
               where p.MaKy == maky && p.MaLop == malop && p.MaNam == manam
               select  p.TrangThaiHK ;
       if (c.First() == true)
       {
           ckb.Checked = true;
       }
       if (c.First() == false)
       { 
           ckb.Checked = false;
       }
   }

}